%{

#include "fivep.h"
#include "malloc.h"
#include "stdlib.h"
#include "string.h"

extern unsigned int line;
extern unsigned int wPos;
extern char linebuf[ 500 ];
extern unsigned int tokenpos, lineno;
extern unsigned int wBlanks;

%}

String           \"[^\"]*\"
Token            [\|\$_0-9A-Z\@\:=\+\-\*\/;\\]+
Spaces           [ \t]+

%s  COMMENT1 COMMENT2

%%

"/*"             BEGIN COMMENT1;
<COMMENT1>"*/"   BEGIN 0;
<COMMENT1>\n     lineno++;
<COMMENT1>.*     yyless( 1 );

"//"             BEGIN COMMENT2;
<COMMENT2>.*\n   BEGIN 0;

{Spaces}         wBlanks = strlen( yytext );
\n.*             lineno++; tokenpos = 0; strcpy( linebuf, yytext + 1 ); yyless( 1 ); return '\n';
;\n              lineno++;

"#xcommand"|"#command" yylval.string = strdup( yytext ); tokenpos += yyleng; return XCOMMAND;
"#include"       yylval.string = strdup( yytext ); tokenpos += yyleng; return INCLUDE;
"#xtranslate"    yylval.string = strdup( yytext ); tokenpos += yyleng; return XTRANSLATE;
"#define"        yylval.string = strdup( yytext ); tokenpos += yyleng; return DEFINE;
"#ifdef"         yylval.string = strdup( yytext ); tokenpos += yyleng; return IFDEF;
"#ifndef"        yylval.string = strdup( yytext ); tokenpos += yyleng; return IFNDEF;
"#else"          yylval.string = strdup( yytext ); tokenpos += yyleng; return ELSE;
"#endif"         yylval.string = strdup( yytext ); tokenpos += yyleng; return ENDIF;
"=>"             yylval.string = strdup( yytext ); tokenpos += yyleng; return ARROW;
"..."            yylval.string = strdup( yytext ); tokenpos += yyleng; return DOTS;
"\{"             tokenpos += 1; return '{';
"\}"             tokenpos += 1; return '}';

{Token}          yylval.string = strdup( yytext ); tokenpos += yyleng; return TOKEN;
[<\[\]>\{\}\,\(\)]   tokenpos += 1; return yytext[ 0 ];
{String}         yylval.string = strdup( yytext ); tokenpos += yyleng; return STRING;

%%
